home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWFiles / SLFileSp.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  23.4 KB  |  784 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLFileSp.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWSOMENV_H
  13. #include "FWSOMEnv.h"
  14. #endif
  15.  
  16. #ifndef FWFILESY_H
  17. #include "FWFileSy.h"
  18. #endif
  19.  
  20. #ifndef FWEXCLIB_H
  21. #include "FWExcLib.h"
  22. #endif
  23.  
  24. #ifndef SLFILPAR_H
  25. #include "SLFilPar.h"
  26. #endif
  27.  
  28. #ifndef FWBNDSTR_H
  29. #include "FWBndStr.h"
  30. #endif
  31.  
  32. #ifndef SLFILESY_H
  33. #include "SLFileSy.h"
  34. #endif
  35.  
  36. #ifndef FWPRIDEB_H
  37. #include "FWPriDeb.h"
  38. #endif
  39.  
  40. #if defined(FW_BUILD_MAC) && !defined(__ERRORS__)
  41. #include <Errors.h>
  42. #endif
  43.  
  44. #if defined(FW_BUILD_MAC) && !defined(__FINDER__)
  45. #include <Finder.h>
  46. #endif
  47.  
  48. #if defined(FW_BUILD_WIN) && !defined(__IO_H)
  49. #include <io.h>
  50. #endif
  51.  
  52. /*
  53.  *  This file was generated by the SOM Compiler.
  54.  *  Generated using: 
  55.  *      SOM Emitter emitxtm.dll: 2.33
  56.  */
  57.  
  58. #define FW_OFileSpecification_Class_Source
  59. #define FW_ODirectorySpecification_Class_Source
  60. #include "SLFileSp.xih"
  61.  
  62.  
  63. #ifdef FW_BUILD_MAC
  64. #pragma segment File
  65. #endif
  66.  
  67. //----------------------------------------------------------------------------------------
  68. // Forward definitions
  69. //----------------------------------------------------------------------------------------
  70.  
  71. static void failOnError(short theError);
  72.  
  73.  
  74. //========================================================================================
  75. // FW_CPrivFileSpecification
  76. //    This struct contains the private implementation for FW_OFileSpecification
  77. //========================================================================================
  78.  
  79. class FW_CPrivFileSpecification
  80. {
  81. #ifdef FW_BUILD_WIN
  82. public:
  83.     FW_DECLARE_AUTO(FW_CPrivFileSpecification);
  84.  
  85.     FW_CString fFileInfo;
  86. #endif
  87.  
  88. #ifdef FW_BUILD_MAC
  89. public:
  90.     FW_CPrivFileSpecification() :
  91.         fFileType(FW_kDefaultFileType), 
  92.         fCreatorType(FW_kDefaultCreatorType)
  93.     {
  94.         fFileInfo.vRefNum = 0;
  95.         fFileInfo.parID = 0;
  96.         fFileInfo.name[0] = 0;
  97.     }
  98.  
  99.     FSSpec fFileInfo;
  100.     OSType fFileType;
  101.     OSType fCreatorType;
  102. #endif 
  103. };
  104.  
  105.  
  106. #ifdef FW_BUILD_WIN
  107. FW_DEFINE_AUTO(FW_CPrivFileSpecification);
  108. #endif 
  109.  
  110.  
  111.  
  112. //========================================================================================
  113. //    class FW_OFileSpecification
  114. //========================================================================================
  115.  
  116.  
  117. //----------------------------------------------------------------------------------------
  118. //    FW_OFileSpecification__InitFromFileName
  119. //  Create a file specification from a full or partial pathname.  In the case of
  120. //    a partial pathname, the specification will use the current default
  121. //    directory to build a full pathname.
  122. //----------------------------------------------------------------------------------------
  123.  
  124. SOM_Scope void  SOMLINK FW_OFileSpecification__InitFromFileName(FW_OFileSpecification *somSelf, Environment *ev,
  125.         FW_HString fileName)
  126. {
  127.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  128.  
  129.     FW_SOM_TRY
  130.     {
  131.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  132.         FW_CString fileNameStr(fileName);
  133.  
  134. #ifdef FW_BUILD_WIN
  135.         rep.fFileInfo = fileNameStr;
  136.         FW_PrivFileSystemParser_WinExpandPartialPath(rep.fFileInfo);
  137.  
  138.         // Verify that path exists.
  139.         FW_CString tempString;
  140.         if (!FW_PrivFileSystemParser_WinGetPathName(rep.fFileInfo, tempString))
  141.             failOnError(FW_xPathNotFound);
  142.  
  143.         FW_SOMEnvironment ev;
  144.         if (!FW_PrivFileSystem_WinPathExists(ev, tempString))
  145.             failOnError(FW_xPathNotFound);
  146. #endif
  147.  
  148. #ifdef FW_BUILD_MAC
  149.         FW_PlatformError theError = FW_xNoError;
  150.         Str255 macFileName;
  151.     
  152.         rep.fFileType = FW_kDefaultFileType; 
  153.         rep.fCreatorType = FW_kDefaultCreatorType;
  154.  
  155.         fileNameStr.ExportPascal(macFileName);
  156.  
  157.         theError = ::FSMakeFSSpec(0, 0, macFileName, &rep.fFileInfo);
  158.         if ((theError != FW_xNoError) && (theError != FW_xNoFileFound))
  159.         {
  160.             rep.fFileInfo.vRefNum = 0;
  161.             rep.fFileInfo.parID = 0;
  162.             FW_ASSERT(fileNameStr.GetByteLength() < 64);
  163.             fileNameStr.ExportPascal(rep.fFileInfo.name);
  164.             FW_Failure(theError);
  165.         }
  166.     #endif
  167.     }
  168.     FW_SOM_CATCH
  169. }
  170.  
  171.  
  172. //----------------------------------------------------------------------------------------
  173. //    FW_OFileSpecification__InitFromDirectoryAndName
  174. //  Create a file specification from a directory and a file name.  The file name
  175. //    should include any extensions that might be necessary.
  176. //----------------------------------------------------------------------------------------
  177.  
  178. SOM_Scope void  SOMLINK FW_OFileSpecification__InitFromDirectoryAndName(FW_OFileSpecification *somSelf, Environment *ev,
  179.         FW_ODirectorySpecification* directory,
  180.         FW_HString fileName)
  181. {
  182.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  183.  
  184.     FW_SOM_TRY
  185.     {
  186.         FW_CString fileNameStr(fileName);
  187.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  188.  
  189. #ifdef FW_BUILD_WIN
  190.         directory->GetFullPath(ev, rep.fFileInfo);
  191.  
  192.         if (fileNameStr.GetByteLength() > 0)
  193.             FW_PrivFileSystemParser_AddDelimiter(rep.fFileInfo);
  194.  
  195.         rep.fFileInfo += fileNameStr;
  196.  
  197.         // Verify that path exists.
  198.         FW_CString tempString;
  199.         if (!FW_PrivFileSystemParser_WinGetPathName(rep.fFileInfo, tempString))
  200.             failOnError(FW_xPathNotFound);
  201.  
  202.         FW_SOMEnvironment ev;
  203.         if (!FW_PrivFileSystem_WinPathExists(ev, tempString))
  204.             failOnError(FW_xPathNotFound);
  205. #endif
  206.  
  207. #ifdef FW_BUILD_MAC
  208.         FW_PlatformError theError = FW_xNoError;
  209.         Str255 macFileName;
  210.         FW_CString255 partialPathName;
  211.  
  212.         rep.fFileType = FW_kDefaultFileType; 
  213.         rep.fCreatorType = FW_kDefaultCreatorType;
  214.  
  215.         directory->MacGetFSSpec(ev, &rep.fFileInfo);
  216.         partialPathName.ReplaceAll((FW_PascalChar*)&rep.fFileInfo.name);
  217.         partialPathName.Prepend(&FW_kPathDelimiter, 1);
  218.  
  219.         FW_PrivFileSystemParser_AddDelimiter(partialPathName);
  220.         partialPathName += fileNameStr;
  221.         partialPathName.ExportPascal(macFileName);
  222.  
  223.         theError = ::FSMakeFSSpec(rep.fFileInfo.vRefNum, rep.fFileInfo.parID, macFileName, &rep.fFileInfo);
  224.         if ((theError != FW_xNoError) && (theError != FW_xNoFileFound))
  225.         {
  226.             FSSpec dirFSSpec;
  227.             directory->MacGetFSSpec(ev, &dirFSSpec);
  228.             
  229.             rep.fFileInfo.vRefNum = dirFSSpec.vRefNum;
  230.             rep.fFileInfo.parID = dirFSSpec.parID;
  231.             
  232.             FW_ASSERT(fileNameStr.GetByteLength() < 64);
  233.             partialPathName.ExportPascal(rep.fFileInfo.name);
  234.             
  235.             FW_Failure(theError);
  236.         }
  237. #endif
  238.     }
  239.     FW_SOM_CATCH
  240. }
  241.  
  242.  
  243. //----------------------------------------------------------------------------------------
  244. //    FW_OFileSpecification__GetName
  245. //  Get the name of the file.
  246. //----------------------------------------------------------------------------------------
  247.  
  248. SOM_Scope void  SOMLINK FW_OFileSpecification__GetName(FW_OFileSpecification *somSelf, Environment *ev,
  249.         FW_HString* fileName)
  250. {
  251.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  252.  
  253.     FW_SOM_TRY
  254.     {
  255.         FW_CString fileNameStr(*fileName);
  256.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  257. //        FW_PlatformError theError = FW_xNoError;
  258.  
  259. #ifdef FW_BUILD_WIN
  260.         FW_CString parsedName;
  261.  
  262.         if (FW_PrivFileSystemParser_GetFileName(rep.fFileInfo, parsedName))
  263.             fileNameStr = parsedName;
  264.         else
  265.             failOnError(FW_kBadFileName);
  266. #endif
  267.  
  268. #ifdef FW_BUILD_MAC
  269.         fileNameStr.ReplaceAll(rep.fFileInfo.name);
  270. #endif
  271.     }
  272.     FW_SOM_CATCH
  273. }
  274.  
  275.  
  276. //----------------------------------------------------------------------------------------
  277. //    FW_OFileSpecification__GetParentDirectory
  278. //  Returns the path information for this file.
  279. //----------------------------------------------------------------------------------------
  280.  
  281. SOM_Scope FW_ODirectorySpecification*  SOMLINK FW_OFileSpecification__GetParentDirectory(FW_OFileSpecification *somSelf, Environment *ev)
  282. {
  283.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  284.  
  285.     FW_SOM_TRY
  286.     {
  287.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  288.         FW_ODirectorySpecification* returnDirectory = new FW_ODirectorySpecification;
  289.  
  290. #ifdef FW_BUILD_WIN
  291.         FW_CString tempPathName;
  292.  
  293.         if (FW_PrivFileSystemParser_WinGetPathName(rep.fFileInfo, tempPathName))
  294.         {
  295.             returnDirectory->InitFromFileName(ev, tempPathName);
  296.         }
  297.         else
  298.         {
  299.             // Path should already have been verified.
  300.             failOnError(FW_xPathNotFound);
  301.         }
  302. #endif
  303.  
  304. #ifdef FW_BUILD_MAC    
  305.         failOnError(FW_PrivFileSystemParser_MacGenerateDirectory(rep.fFileInfo.vRefNum, rep.fFileInfo.parID, returnDirectory));
  306. #endif
  307.  
  308.         return returnDirectory;
  309.     }
  310.     FW_SOM_CATCH
  311.     return 0;
  312. }
  313.  
  314.  
  315. //----------------------------------------------------------------------------------------
  316. //    FW_OFileSpecification__GetFullPath
  317. //  Returns the fully qualified path and file name for this file.  The user should
  318. //    pass in a dynamic string so as to guarantee that the path will fit inside
  319. //    it.
  320. //----------------------------------------------------------------------------------------
  321.  
  322. SOM_Scope void  SOMLINK FW_OFileSpecification__GetFullPath(FW_OFileSpecification *somSelf, Environment *ev,
  323.         FW_HString* fullPathName)
  324. {
  325.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  326.  
  327.     FW_SOM_TRY
  328.     {
  329.         FW_CString fullPathNameStr(*fullPathName);
  330.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  331.  
  332. #ifdef FW_BUILD_WIN
  333.         fullPathNameStr = rep.fFileInfo;
  334. #endif
  335.  
  336. #ifdef FW_BUILD_MAC
  337.         fullPathNameStr.ReplaceAll(rep.fFileInfo.name);
  338.         FW_PlatformError theError = FW_xNoError;
  339.     
  340.         theError = FW_PrivFileSystemParser_MacGenerateFullPathName(rep.fFileInfo.vRefNum, rep.fFileInfo.parID, fullPathNameStr);
  341.         failOnError(theError);
  342. #endif
  343.     }
  344.     FW_SOM_CATCH
  345. }
  346.  
  347.  
  348. //----------------------------------------------------------------------------------------
  349. //    FW_OFileSpecification__IsSameAs
  350. //  Does this file represent the same file as theOtherFile.
  351. //----------------------------------------------------------------------------------------
  352.  
  353. SOM_Scope FW_Boolean  SOMLINK FW_OFileSpecification__IsSameAs(FW_OFileSpecification *somSelf, Environment *ev,
  354.         FW_OFileSpecification* theOtherFile)
  355. {
  356.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  357.  
  358.     FW_SOM_TRY
  359.     {
  360.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  361.         FW_CPrivFileSpecification& otherRep = *FW_OFileSpecificationGetData(theOtherFile)->fRep;
  362.  
  363. #ifdef FW_BUILD_WIN
  364.         FW_CString tempString1(rep.fFileInfo);
  365.         FW_CString tempString2(otherRep.fFileInfo);
  366.     
  367.         tempString1.ToUpper();
  368.         tempString2.ToUpper();
  369.         return (tempString1 == tempString2);
  370. #endif
  371.  
  372. #ifdef FW_BUILD_MAC
  373.         if ((rep.fFileInfo.vRefNum == otherRep.fFileInfo.vRefNum) && (rep.fFileInfo.parID == otherRep.fFileInfo.parID))
  374.         {
  375.             if (rep.fFileType == otherRep.fFileType && rep.fCreatorType == otherRep.fCreatorType)
  376.             {
  377.                 // [jkp] this is a clumsy way to do the comparison.  Can the strings be inited 
  378.                 // with the fFileInfo.name fields?
  379.                 FW_CString fileName1;
  380.                 FW_CString fileName2;
  381.         
  382.                 fileName1.ReplaceAll((FW_PascalChar*)&rep.fFileInfo.name);
  383.                 fileName2.ReplaceAll((FW_PascalChar*)&otherRep.fFileInfo.name);
  384.         
  385.                 fileName1.ToUpper();
  386.                 fileName2.ToUpper();
  387.                 return (fileName1 == fileName2);
  388.             }
  389.         }
  390.     
  391.         return (FALSE);
  392. #endif
  393.     }
  394.     FW_SOM_CATCH
  395.     return 0;
  396. }
  397.  
  398.  
  399. //----------------------------------------------------------------------------------------
  400. //    FW_OFileSpecification__AssignOFileSpecification
  401. //  Copy all of the file information from theOtherFile so that this file spec
  402. //    represents the same file.
  403. //----------------------------------------------------------------------------------------
  404.  
  405. SOM_Scope void  SOMLINK FW_OFileSpecification__AssignOFileSpecification(FW_OFileSpecification *somSelf, Environment *ev,
  406.         FW_OFileSpecification* theOtherFile)
  407. {
  408.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  409.  
  410.     FW_SOM_TRY
  411.     {
  412.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  413.         FW_CPrivFileSpecification& otherRep = *FW_OFileSpecificationGetData(theOtherFile)->fRep;
  414.  
  415.         rep.fFileInfo = otherRep.fFileInfo;
  416. #ifdef FW_BUILD_MAC
  417.         rep.fFileType = otherRep.fFileType;
  418.         rep.fCreatorType = otherRep.fCreatorType;
  419. #endif
  420.     }
  421.     FW_SOM_CATCH
  422. }
  423.  
  424.  
  425. //----------------------------------------------------------------------------------------
  426. //    FW_OFileSpecification__AssignFileName
  427. //  Change the name of this file to fileName.  fileName may be a partial pathName.
  428. //  This does not change any of the existing path information.
  429. //----------------------------------------------------------------------------------------
  430.  
  431. SOM_Scope void  SOMLINK FW_OFileSpecification__AssignFileName(FW_OFileSpecification *somSelf, Environment *ev,
  432.         FW_HString fileNameRep)
  433. {
  434.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  435.  
  436.     FW_SOM_TRY
  437.     {
  438.         FW_CString fileName(fileNameRep);
  439.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  440. #ifdef FW_BUILD_WIN
  441.         FW_CString tempPathName;
  442.  
  443.         if (FW_PrivFileSystemParser_WinGetPathName(rep.fFileInfo, tempPathName))
  444.         {
  445.             FW_PrivFileSystemParser_AddDelimiter(tempPathName);
  446.             rep.fFileInfo = tempPathName;
  447.         }
  448.  
  449.         rep.fFileInfo += fileName;
  450.     
  451.         // Verify that path exists.
  452.         FW_CString tempString;
  453.         if (!FW_PrivFileSystemParser_WinGetPathName(rep.fFileInfo, tempString))
  454.             failOnError(FW_xPathNotFound);
  455.  
  456.         FW_SOMEnvironment ev;
  457.         if (!FW_PrivFileSystem_WinPathExists(ev, tempString))
  458.             failOnError(FW_xPathNotFound);
  459. #endif
  460.  
  461. #ifdef FW_BUILD_MAC
  462.         FW_PlatformError theError = FW_xNoError;
  463.         short vRefNum = rep.fFileInfo.vRefNum;
  464.         long dirID = rep.fFileInfo.parID;
  465.         Str255 macFileName;
  466.     
  467.         rep.fFileType = FW_kDefaultFileType; 
  468.         rep.fCreatorType = FW_kDefaultCreatorType;
  469.  
  470.         fileName.ExportPascal(macFileName);
  471.  
  472.         theError = ::FSMakeFSSpec(vRefNum, dirID, macFileName, &rep.fFileInfo);
  473.         if ((theError != FW_xNoError) && (theError != FW_xNoFileFound))
  474.         {
  475.             rep.fFileInfo.vRefNum = vRefNum;
  476.             rep.fFileInfo.parID = dirID;
  477.             FW_ASSERT(fileName.GetByteLength() < 64);
  478.             fileName.ExportPascal(rep.fFileInfo.name);
  479.             FW_Failure(theError);
  480.         }
  481. #endif
  482.     }
  483.     FW_SOM_CATCH
  484. }
  485.  
  486.  
  487. #ifdef FW_BUILD_WIN
  488. //----------------------------------------------------------------------------------------
  489. //    FW_OFileSpecification__WinGetDrive
  490. //----------------------------------------------------------------------------------------
  491.  
  492. SOM_Scope char  SOMLINK FW_OFileSpecification__WinGetDrive(FW_OFileSpecification *somSelf, Environment *ev)
  493. {
  494.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  495.  
  496.     FW_SOM_TRY
  497.     {
  498.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  499.         FW_CharacterPosition colonPosition = -1;
  500.         FW_CString driveName;
  501.         FW_Char driveLetter = '\0';
  502.  
  503.         // If there's no drive information in the path, get the default drive information.
  504.         if (!FW_PrivFileSystemParser_WinGetDrivePath(rep.fFileInfo, driveName))
  505.             failOnError(FW_kBadFileName);
  506.  
  507.         if (!driveName.FindCharacter(FW_kDriveDelimiter, colonPosition))
  508.             failOnError(FW_kNoSuchVolume);
  509.  
  510.         if (colonPosition > 1)
  511.             failOnError(FW_kNoSuchVolume);
  512.         
  513.         driveName.ToLower();
  514.     
  515.         driveLetter = (char) driveName[(FW_CharacterPosition)(colonPosition - 1)];
  516.  
  517.         if ((driveLetter < 'a') || (driveLetter > 'z'))
  518.             failOnError(FW_kBadFileName);
  519.  
  520.         return (driveLetter);
  521.     }
  522.     FW_SOM_CATCH
  523.     return 0;
  524. }
  525. #endif
  526.  
  527.  
  528. #ifdef FW_BUILD_WIN
  529. //----------------------------------------------------------------------------------------
  530. //    FW_OFileSpecification__WinGetExtension
  531. //----------------------------------------------------------------------------------------
  532.  
  533. SOM_Scope void  SOMLINK FW_OFileSpecification__WinGetExtension(FW_OFileSpecification *somSelf, Environment *ev,
  534.         FW_HString* extension)
  535. {
  536.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  537.  
  538.     FW_SOM_TRY
  539.     {
  540.         FW_CString extensionStr(*extension);
  541.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  542.  
  543.         if (!FW_PrivFileSystemParser_GetExtension(rep.fFileInfo, extensionStr))
  544.             extensionStr = "";
  545.     }
  546.     FW_SOM_CATCH
  547. }
  548. #endif
  549.  
  550.  
  551. #ifdef FW_BUILD_WIN
  552. //----------------------------------------------------------------------------------------
  553. //    FW_OFileSpecification__WinSetExtension
  554. //----------------------------------------------------------------------------------------
  555.  
  556. SOM_Scope void  SOMLINK FW_OFileSpecification__WinSetExtension(FW_OFileSpecification *somSelf, Environment *ev,
  557.         FW_HString extension)
  558. {
  559.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  560.  
  561.     FW_SOM_TRY
  562.     {
  563.         FW_CString extensionStr(extension);
  564.         FW_CPrivFileSpecification& rep = *somThis->fRep;
  565.         FW_CString newFileInfo;
  566.  
  567.         FW_PrivFileSystemParser_ChangeExtension(rep.fFileInfo, extensionStr, newFileInfo);
  568.         rep.fFileInfo = newFileInfo;
  569.     }
  570.     FW_SOM_CATCH
  571. }
  572. #endif
  573.  
  574.  
  575. #ifdef FW_BUILD_MAC
  576. //----------------------------------------------------------------------------------------
  577. //    FW_OFileSpecification__AssignFileSpec
  578. //  This specifier will now represent the file described by macSpec.
  579. //----------------------------------------------------------------------------------------
  580.  
  581. SOM_Scope void  SOMLINK FW_OFileSpecification__AssignFileSpec(FW_OFileSpecification *somSelf, Environment *ev,
  582.         FSSpec* macSpec)
  583. {
  584. FW_UNUSED(ev);
  585.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  586.     FW_CPrivFileSpecification& rep = *somThis->fRep;
  587.  
  588.     rep.fFileInfo = *macSpec;
  589.     rep.fFileType = FW_kDefaultFileType; 
  590.     rep.fCreatorType = FW_kDefaultCreatorType;
  591. }
  592. #endif
  593.  
  594.  
  595. #ifdef FW_BUILD_MAC
  596. //----------------------------------------------------------------------------------------
  597. //    FW_OFileSpecification__MacGetFSSpec
  598. //  Return a Macintosh FSSpec that points to this file.
  599. //----------------------------------------------------------------------------------------
  600.  
  601. SOM_Scope void  SOMLINK FW_OFileSpecification__MacGetFSSpec(FW_OFileSpecification *somSelf, Environment *ev,
  602.         FSSpec* macSpec)
  603. {
  604. FW_UNUSED(ev);
  605.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  606.     FW_CPrivFileSpecification& rep = *somThis->fRep;
  607.  
  608.     *macSpec = rep.fFileInfo;
  609. }
  610. #endif
  611.  
  612.  
  613. #ifdef FW_BUILD_MAC
  614. //----------------------------------------------------------------------------------------
  615. //    FW_OFileSpecification__MacSetTypeAndCreator
  616. //----------------------------------------------------------------------------------------
  617.  
  618. SOM_Scope void  SOMLINK FW_OFileSpecification__MacSetTypeAndCreator(FW_OFileSpecification *somSelf, Environment *ev,
  619.         FW_ResourceType aFileType,
  620.         FW_ResourceType aCreatorType)
  621. {
  622. FW_UNUSED(ev);
  623.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  624.     FW_CPrivFileSpecification& rep = *somThis->fRep;
  625.  
  626.     rep.fFileType = aFileType; 
  627.     rep.fCreatorType = aCreatorType;
  628. }
  629. #endif
  630.  
  631.  
  632. #ifdef FW_BUILD_MAC
  633. //----------------------------------------------------------------------------------------
  634. //    FW_OFileSpecification__MacGetTypeAndCreator
  635. //  Accessors to the type and creator of the file specification.
  636. //----------------------------------------------------------------------------------------
  637.  
  638. SOM_Scope void  SOMLINK FW_OFileSpecification__MacGetTypeAndCreator(FW_OFileSpecification *somSelf, Environment *ev,
  639.         FW_ResourceType* aFileType,
  640.         FW_ResourceType* aCreatorType)
  641. {
  642. FW_UNUSED(ev);
  643.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  644.     FW_CPrivFileSpecification& rep = *somThis->fRep;
  645.  
  646.     *aFileType = rep.fFileType; 
  647.     *aCreatorType = rep.fCreatorType;
  648. }
  649. #endif
  650.  
  651.  
  652. //----------------------------------------------------------------------------------------
  653. //    FW_OFileSpecification__somInit
  654. //----------------------------------------------------------------------------------------
  655.  
  656. SOM_Scope void  SOMLINK FW_OFileSpecification__somInit(FW_OFileSpecification *somSelf)
  657. {
  658. FW_UNUSED(somSelf);
  659.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  660.  
  661. //    FW_OFileSpecification_parent_SOMObject_somInit(somSelf);
  662.  
  663.     somThis->fRep = new FW_CPrivFileSpecification;
  664. }
  665.  
  666.  
  667. //----------------------------------------------------------------------------------------
  668. //    FW_OFileSpecification__somUninit
  669. //----------------------------------------------------------------------------------------
  670.  
  671. SOM_Scope void  SOMLINK FW_OFileSpecification__somUninit(FW_OFileSpecification *somSelf)
  672. {
  673.     FW_OFileSpecificationData *somThis = FW_OFileSpecificationGetData(somSelf);
  674.  
  675.     FW_SOM_UNINIT_TRY
  676.     {
  677.         delete somThis->fRep;
  678.  
  679. //        FW_OFileSpecification_parent_SOMObject_somUninit(somSelf);
  680.     }
  681.     FW_SOM_UNINIT_CATCH
  682. }
  683.  
  684.  
  685.  
  686. //========================================================================================
  687. //    class FW_ODirectorySpecification
  688. //========================================================================================
  689.  
  690.  
  691. //----------------------------------------------------------------------------------------
  692. //    FW_ODirectorySpecification__AppendDirectoryName
  693. //  Add directoryName to the end of this path.  This routine will add a path
  694. //    separator so that the user does not need to.  The remaining path information
  695. //    may specify a subdirectory or parent directory, but must start from this
  696. //    directory.
  697. //----------------------------------------------------------------------------------------
  698.  
  699. SOM_Scope void  SOMLINK FW_ODirectorySpecification__AppendDirectoryName(FW_ODirectorySpecification *somSelf, Environment *ev,
  700.         FW_HString directoryNameRep)
  701. {
  702.     /* FW_ODirectorySpecificationData *somThis = FW_ODirectorySpecificationGetData(somSelf); */
  703.     FW_ODirectorySpecificationMethodDebug("FW_ODirectorySpecification","FW_ODirectorySpecification__AppendDirectoryName");
  704.  
  705.     FW_SOM_TRY
  706.     {
  707.         FW_CString directoryName(directoryNameRep);
  708.         FW_CString tempName;
  709.  
  710.         // Get our current name
  711.         somSelf->GetName(ev, tempName);
  712.  
  713. #ifdef FW_BUILD_MAC
  714.         // Need to add a leading delimiter to indicate this is a partial path.
  715.         tempName.Prepend(&FW_kPathDelimiter, 1);
  716. #endif
  717.  
  718.         tempName += FW_kPathDelimiter;
  719.         tempName += directoryName;
  720.  
  721.         // Set the name to that new string
  722.         somSelf->AssignFileName(ev, tempName);
  723.     }
  724.     FW_SOM_CATCH
  725. }
  726.  
  727.  
  728. //----------------------------------------------------------------------------------------
  729. //    FW_ODirectorySpecification__GetFullPath
  730. //----------------------------------------------------------------------------------------
  731.  
  732. SOM_Scope void  SOMLINK FW_ODirectorySpecification__GetFullPath(FW_ODirectorySpecification *somSelf, Environment *ev,
  733.         FW_HString* fullPathName)
  734. {
  735.     /* FW_ODirectorySpecificationData *somThis = FW_ODirectorySpecificationGetData(somSelf); */
  736.     FW_ODirectorySpecificationMethodDebug("FW_ODirectorySpecification","FW_ODirectorySpecification__GetFullPath");
  737.  
  738.     FW_SOM_TRY
  739.     {
  740.         FW_CString fullPathNameStr(*fullPathName);
  741.         FW_ODirectorySpecification_parent_FW_OFileSpecification_GetFullPath(somSelf,ev,fullPathNameStr);
  742.         FW_PrivFileSystemParser_AddDelimiter(fullPathNameStr);
  743.     }
  744.     FW_SOM_CATCH
  745. }
  746.  
  747.  
  748. //----------------------------------------------------------------------------------------
  749. //    FW_ODirectorySpecification__somInit
  750. //----------------------------------------------------------------------------------------
  751.  
  752. SOM_Scope void  SOMLINK FW_ODirectorySpecification__somInit(FW_ODirectorySpecification *somSelf)
  753. {
  754.     // FW_ODirectorySpecificationData *somThis = FW_ODirectorySpecificationGetData(somSelf);
  755.     FW_ODirectorySpecificationMethodDebug("FW_ODirectorySpecification","FW_ODirectorySpecification__somInit");
  756.  
  757. //    FW_ODirectorySpecification_parent_FW_OFileSpecification_somInit(somSelf);
  758.  
  759.     // Assign the null directory to this item
  760.     FW_SOMEnvironment ev;
  761.  
  762.     FW_SOM_TRY
  763.     {
  764.         FW_CString nullPath;
  765.         somSelf->InitFromFileName(ev, nullPath);
  766.     }
  767.     FW_SOM_CATCH
  768. }
  769.  
  770.  
  771. //----------------------------------------------------------------------------------------
  772. //    failOnError
  773. //----------------------------------------------------------------------------------------
  774.  
  775. static void failOnError(short theError)
  776. {
  777.     // JEL: I don't know why kNoFileFound is not an error.
  778.     // Ideally, we should eliminate this method entirely, and just
  779.     // call FW_FailOnError directly, and only check for kNoFileFound
  780.     // where it is definitely not an error.
  781.     if (theError != FW_xNoFileFound)
  782.         FW_FailOnError(theError);
  783. }
  784.